
package br.praticas.projetoacademia.views;

import br.praticas.projetoacademia.dao.ContatoDao;
import br.praticas.projetoacademia.dao.EnderecoDao;
import br.praticas.projetoacademia.dao.SecretariaDao;
import br.praticas.projetoacademia.models.Contato;
import br.praticas.projetoacademia.models.Endereco;
import br.praticas.projetoacademia.models.Secretaria;
import br.praticas.projetoacademia.util.Check;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.RowFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

/**
 *@since 16/11/2014
 * @author lucia
 * @see classe EnderecoDao
 * @see classe ContatoDao
 * @see classe Secretaria
 * @see classe SecretariaDap
 */
public class SecretariaView extends javax.swing.JDialog {

    Secretaria secretaria = new Secretaria();
    Endereco enderecos = new Endereco();
    Contato contatos = new Contato();
    SecretariaDao daoSecretaria = new SecretariaDao();
    EnderecoDao daoEndereco = new EnderecoDao();
    ContatoDao daoContato = new ContatoDao();
    List<Secretaria> listaModelSecretaria = new ArrayList<>();
    List<Endereco> listaModelEndereco = new ArrayList<>();
    List<Contato> listaModelContato = new ArrayList<>();
    String tipoCadastro;

    public SecretariaView() {
        initComponents();
        setLocationRelativeTo(null);
        this.carregarSecretarias();
    }
    /**
     * Metodo que lista todos as secretarias em uma tabela, com seus respectivos
     * dados.
     */
    private void carregarSecretarias() {
            String colunas[] = {"Nome", "CPF", "Salário", "Cidade", "Bairro",
                "Cep", "Uf", "Celular", "Fixo", "Email", "Número", "Rua"};
            listaModelSecretaria = daoSecretaria.listarSecretarias();
            String dados[][] = new String[listaModelSecretaria.size()][12];
            //CARREGA OS DADOS DA LISTA NA TABELA
            int cont = listaModelSecretaria.size();
            for (int i = 0; i < cont; i++) {
                dados[i][0] = listaModelSecretaria.get(i).getNome();
                dados[i][1] = listaModelSecretaria.get(i).getCpf();
                dados[i][2] = listaModelSecretaria.get(i).getSalario();
                dados[i][3] = listaModelSecretaria.get(i).getContato().getCelular();
                dados[i][4] = listaModelSecretaria.get(i).getContato().getTelefoneFixo();
                dados[i][5] = listaModelSecretaria.get(i).getContato().getEmail();
                dados[i][6] = listaModelSecretaria.get(i).getEndereco().getBairro();
                dados[i][7] = listaModelSecretaria.get(i).getEndereco().getCep();
                dados[i][8] = listaModelSecretaria.get(i).getEndereco().getCidade();
                dados[i][9] = listaModelSecretaria.get(i).getEndereco().getEstado();
                dados[i][10] = listaModelSecretaria.get(i).getEndereco().getNumero();
                dados[i][11] = listaModelSecretaria.get(i).getEndereco().getRua();
            }
            TableModel model = new DefaultTableModel(dados, colunas);
            tabela.setModel(model);
    }
    /**
     * Metodo que limpa os dados da interface secretaria
     */
    private void limpar() {
        Cpf.setText("");
        Nome.setText("");
        bairo.setText("");
        cidade.setText("");
        cep.setText("");
        uf.setText("");
        celular.setText("");
        fixo.setText("");
        email.setText("");
        Salario.setText("");

    }
    /**
     * Metodo que desabilita os campos e botoes da tela secretaria
     */
    protected void desabilitarCampos() {
        Nome.setEditable(false);
        Cpf.setEditable(false);
        bairo.setEditable(false);
        numero.setEditable(false);
        rua.setEditable(false);
        cidade.setEditable(false);
        cep.setEditable(false);
        uf.setEditable(false);
        celular.setEditable(false);
        fixo.setEditable(false);
        email.setEditable(false);
        salvar.setEnabled(false);

    }
    /**
     * Metodo que habilita os campos e botoes da tela secretaria
     */
    private void habilitarCampos() {
        Nome.setEditable(true);
        Cpf.setEditable(true);
        bairo.setEditable(true);
        Salario.setEditable(true);
        cidade.setEditable(true);
        cep.setEditable(true);
        uf.setEditable(true);
        celular.setEditable(true);
        fixo.setEditable(true);
        email.setEditable(true);
        rua.setEditable(true);
        numero.setEditable(true);
        bairo.setEditable(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        excluir = new javax.swing.JToggleButton();
        alterar = new javax.swing.JToggleButton();
        cancelar = new javax.swing.JToggleButton();
        novo = new javax.swing.JToggleButton();
        salvar = new javax.swing.JToggleButton();
        jLabel8 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        Cpf = new javax.swing.JTextField();
        Salario = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        cidade = new javax.swing.JTextField();
        bairo = new javax.swing.JTextField();
        cep = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        uf = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        fixo = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        email = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel16 = new javax.swing.JLabel();
        celular = new javax.swing.JTextField();
        Nome = new javax.swing.JTextField();
        Pesquisa = new javax.swing.JTextField();
        btPesquisaCliente = new javax.swing.JButton();
        numero = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        rua = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabela = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Secretaria");

        excluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/praticas/projetoacademia/imagens/Delete.png"))); // NOI18N
        excluir.setText("Remover");
        excluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                excluirActionPerformed(evt);
            }
        });

        alterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/praticas/projetoacademia/imagens/Modify.png"))); // NOI18N
        alterar.setText("Alterar");
        alterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                alterarActionPerformed(evt);
            }
        });

        cancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/praticas/projetoacademia/imagens/No.png"))); // NOI18N
        cancelar.setText("Cancelar");
        cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarActionPerformed(evt);
            }
        });

        novo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/praticas/projetoacademia/imagens/Add.png"))); // NOI18N
        novo.setText("Novo");
        novo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novoActionPerformed(evt);
            }
        });

        salvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/praticas/projetoacademia/imagens/Save.png"))); // NOI18N
        salvar.setText("Salvar");
        salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarActionPerformed(evt);
            }
        });

        jLabel8.setText("Nome:");

        jLabel10.setText("Cpf:");

        Cpf.setEditable(false);

        Salario.setEditable(false);
        Salario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SalarioActionPerformed(evt);
            }
        });

        jLabel7.setText("Contato:");

        jLabel11.setText("Salario:");

        cidade.setEditable(false);

        bairo.setEditable(false);
        bairo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bairoActionPerformed(evt);
            }
        });

        cep.setEditable(false);

        jLabel6.setText("Cep:");

        uf.setEditable(false);

        jLabel5.setText("Cidade:");

        jLabel13.setText("Telefone Fixo:");

        fixo.setEditable(false);
        fixo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fixoActionPerformed(evt);
            }
        });

        jLabel14.setText("Email:");

        jLabel15.setText("Bairro:");

        email.setEditable(false);
        email.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                emailActionPerformed(evt);
            }
        });

        jLabel2.setText("Endereço:");

        jLabel16.setText("Uf:");

        celular.setEditable(false);
        celular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                celularActionPerformed(evt);
            }
        });

        Nome.setEditable(false);

        Pesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PesquisaActionPerformed(evt);
            }
        });

        btPesquisaCliente.setText("Pesquisar");
        btPesquisaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPesquisaClienteActionPerformed(evt);
            }
        });

        numero.setEditable(false);
        numero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                numeroActionPerformed(evt);
            }
        });

        jLabel17.setText("Rua:");

        rua.setEditable(false);
        rua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ruaActionPerformed(evt);
            }
        });

        jLabel18.setText("Numero:");

        jLabel19.setText("Celelular:");

        tabela.setAutoCreateRowSorter(true);
        tabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome", "Cpf", "Salario", "Cidade", "Bairro", "Cep", "Uf", "Celular", "Fixo", "Email", "Numero", "Rua"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, true, true, true, true, true, true, true, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabela.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        tabela.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(tabela);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(celular, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(fixo, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(email, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel7)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(Pesquisa)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btPesquisaCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel8)
                                .addComponent(Nome, javax.swing.GroupLayout.PREFERRED_SIZE, 368, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, 11, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel10)
                                .addComponent(Cpf, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(Salario, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(jLabel19)
                            .addGap(120, 120, 120)
                            .addComponent(jLabel13)
                            .addGap(82, 82, 82)
                            .addComponent(jLabel14))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(cidade, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(rua, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel17))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel18)
                                    .addGap(0, 0, Short.MAX_VALUE))
                                .addComponent(numero))
                            .addGap(18, 18, 18)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(bairo, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel15))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(72, 72, 72)
                                    .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(cep, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(uf, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel2)
                                .addComponent(jLabel5))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jSeparator3)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addComponent(cancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(excluir, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(alterar, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(novo, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(salvar, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(jSeparator1))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Nome)
                    .addComponent(Cpf, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Salario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel15, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel17)
                        .addComponent(jLabel5))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel16)
                        .addComponent(jLabel6)
                        .addComponent(jLabel18)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bairo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(uf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(numero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addGap(5, 5, 5)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(jLabel13)
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(celular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fixo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btPesquisaCliente))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelar)
                    .addComponent(excluir)
                    .addComponent(alterar)
                    .addComponent(novo)
                    .addComponent(salvar))
                .addGap(19, 19, 19))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
/**
     * Metodo que salva uma secretaria no banco, onde prenche seus respectinos dados
     * esse metodo tambem altera os dados das secretarias.
     * @see metodo AlterarActionPerformed
     */
    private void salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarActionPerformed
      if(tipoCadastro.equals("salvar"))
      {
           JOptionPane.showMessageDialog(null, "Botao errado.", "Ok", JOptionPane.INFORMATION_MESSAGE);
      }
        if (tipoCadastro.equals("novo")) {
            secretaria.setNome(this.Nome.getText());
            secretaria.setSalario(this.Salario.getText());
            secretaria.setCpf(this.Cpf.getText());
            enderecos.setBairro(this.bairo.getText());
            enderecos.setCep(this.cidade.getText());
            enderecos.setBairro(this.bairo.getText());
            enderecos.setCidade(this.cidade.getText());
            enderecos.setEstado(this.uf.getText());
            contatos.setCelular(this.celular.getText());
            contatos.setEmail(this.email.getText());
            contatos.setTelefoneFixo(this.fixo.getText());
            secretaria.setSalario(this.Salario.getText());
            secretaria.setEndereco(enderecos);
            secretaria.setContato(contatos);

            if (tipoCadastro.equals("novo")) {
                daoSecretaria.add(secretaria, contatos, enderecos);
                JOptionPane.showMessageDialog(null, "secretaria cadastrado com sucesso.", "Ok", JOptionPane.INFORMATION_MESSAGE);
            } else if (tipoCadastro.equals("alterar")) {
                daoSecretaria.update(secretaria, contatos, enderecos);
                JOptionPane.showMessageDialog(null, "secretaria editado com sucesso.", "Ok", JOptionPane.INFORMATION_MESSAGE);
            }
            limpar();
            this.desabilitarCampos();
            this.carregarSecretarias();
            
            
        }
    }//GEN-LAST:event_salvarActionPerformed
    /**
     * Metodo que altera os dados de uma secretaria
     */
    private void alterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alterarActionPerformed
        DefaultTableModel modelo = (DefaultTableModel) tabela.getModel();
        int index = tabela.getSelectedRow();
        secretaria = daoSecretaria.buscarSecretaria(index);
        this.Nome.setText(secretaria.getNome());
        this.Cpf.setText(secretaria.getCpf());
        this.bairo.setText(enderecos.getBairro());
        this.cidade.setText(enderecos.getCidade());
        this.cep.setText(enderecos.getEstado());
        this.uf.setText(enderecos.getRua());
        this.celular.setText(contatos.getCelular());
        this.fixo.setText(contatos.getEmail());
        this.email.setText(contatos.getTelefoneFixo());
        this.Salario.setText(secretaria.getSalario());
        tipoCadastro = "alterar";
        habilitarCampos();
    }//GEN-LAST:event_alterarActionPerformed

    private void novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novoActionPerformed
        tipoCadastro = "novo";
        this.habilitarCampos();
    }//GEN-LAST:event_novoActionPerformed

    private void cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarActionPerformed
        disable();
    }//GEN-LAST:event_cancelarActionPerformed
    /**
     * Metodo que exclui uma secretaria atraves da linha selecionada da tabela
     */
    private void excluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excluirActionPerformed
        DefaultTableModel modelo = (DefaultTableModel) tabela.getModel();
        int index = tabela.getSelectedRow();
        secretaria = daoSecretaria.buscarSecretaria(index);
        if (Check.checkNull(secretaria)) {
            JOptionPane.showConfirmDialog(null, "Voce tem certeza que deseja excluir o secretaria selecionado?", "?", JOptionPane.YES_NO_OPTION);
            daoSecretaria.remove(secretaria, contatos, enderecos);
            JOptionPane.showMessageDialog(null, "secretaria excluido com suscesso!");
            carregarSecretarias();
        } else {
            JOptionPane.showMessageDialog(this, "Erro ao Excluir!", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_excluirActionPerformed

    private void SalarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SalarioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_SalarioActionPerformed

    private void bairoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bairoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_bairoActionPerformed

    private void fixoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fixoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_fixoActionPerformed

    private void emailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_emailActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_emailActionPerformed

    private void celularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_celularActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_celularActionPerformed
    /**
     * Metodo busca uma secretaria pelo nome
     */
    private void btPesquisaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPesquisaClienteActionPerformed
        DefaultTableModel tabela = (DefaultTableModel) this.tabela.getModel();
        final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tabela);
        this.tabela.setRowSorter(sorter);
        String text = Pesquisa.getText();
        sorter.setRowFilter(RowFilter.regexFilter(text, 1));
    }//GEN-LAST:event_btPesquisaClienteActionPerformed

    private void PesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PesquisaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_PesquisaActionPerformed

    private void numeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_numeroActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_numeroActionPerformed

    private void ruaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ruaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ruaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SecretariaView().setVisible(true);
            }
        });

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    protected javax.swing.JTextField Cpf;
    protected javax.swing.JTextField Nome;
    protected javax.swing.JTextField Pesquisa;
    protected javax.swing.JTextField Salario;
    private javax.swing.JToggleButton alterar;
    protected javax.swing.JTextField bairo;
    private javax.swing.JButton btPesquisaCliente;
    private javax.swing.JToggleButton cancelar;
    protected javax.swing.JTextField celular;
    protected javax.swing.JTextField cep;
    protected javax.swing.JTextField cidade;
    protected javax.swing.JTextField email;
    private javax.swing.JToggleButton excluir;
    protected javax.swing.JTextField fixo;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JToggleButton novo;
    protected javax.swing.JTextField numero;
    protected javax.swing.JTextField rua;
    private javax.swing.JToggleButton salvar;
    private javax.swing.JTable tabela;
    protected javax.swing.JTextField uf;
    // End of variables declaration//GEN-END:variables
}
